/**
 * @author zyj
 * @date 2022年06月06日 15:18
 */
public class 加入线程 {
    public static void main(String[] args) {
        Thread thread = new Thread("线程A"){
            @Override
            public void run() {
                for (int i = 0; i < 100; i++) {
                    try {
                        sleep(50);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName() + " : " + i);
                }
            }

        };
        thread.start();
        for (int i = 0; i < 100; i++) {
            try {
               Thread.sleep(80);
                System.out.println(Thread.currentThread().getName() + " : " + i);
                if (i == 20){
                   thread.join(50);
               }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
